package com.jiawa.wiki.controller;

import com.jiawa.wiki.req.DocQueryReq;
import com.jiawa.wiki.req.DocSaveReq;
import com.jiawa.wiki.resp.DocQueryResp;
import com.jiawa.wiki.resp.CommomResp;
import com.jiawa.wiki.resp.PageResp;
import com.jiawa.wiki.service.DocService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/doc")
public class DocController {


    @Resource
    private DocService docService;

    @GetMapping("/list")
    public CommomResp list(@Valid DocQueryReq req){
        PageResp<DocQueryResp> list = docService.getlist(req);

        CommomResp<PageResp<DocQueryResp>> resp = new CommomResp<>();
        resp.setContent(list);
        return resp;

    }

    @PostMapping ("/save")
    public CommomResp save(@RequestBody DocSaveReq req){

        CommomResp resp = new CommomResp<>();
        docService.save(req);
        return resp;

    }

    @DeleteMapping("/delete/{id}")
    public CommomResp delete(@PathVariable long id){
        CommomResp resp = new CommomResp<>();

        docService.delete(id);

        return resp;

    }
    @GetMapping("/all")
    public CommomResp all(){
        List<DocQueryResp> list = docService.getall();

        //ctrl+alt+v
        CommomResp<List<DocQueryResp>> resp = new CommomResp<>();
        resp.setContent(list);
        return resp;
    }

}

